#include "ConfigUtil.h"

ConfigUtil* ConfigUtil::configUtil_ = NULL;

ConfigUtil::ConfigUtil() : screenHeight_(0), screenWidth_(0) {

}

ConfigUtil::~ConfigUtil() {

}

bool ConfigUtil::ParseConfig(const std::string filename)
{
    bool isOk = true;
    std::ifstream fin(filename.c_str());

    if (fin.good()) {
        try {
            YAML::Parser parser(fin);
            YAML::Node doc;
            parser.GetNextDocument(doc);
            
            doc["screenWidth"]  >> screenWidth_;
            doc["screenHeight"] >> screenHeight_;

        } catch (YAML::ParserException) {
            LogUtil::Instance()->logError("ConfigUtil", "ParseConfig", 
                "YAML Parser exception.");
            isOk = false;

        } catch (YAML::InvalidScalar is) {
            LogUtil::Instance()->logError("ConfigUtil", "ParseConfig", 
                "YAML Invalid scalar exception.");
            isOk = false;

        } catch (YAML::BadDereference bd) {
            LogUtil::Instance()->logError("ConfigUtil", "ParseConfig", 
                "YAML Bad dereference exception.");
            isOk = false;
        }
        fin.close();

    } else {
        isOk = false;
    }

    return isOk;
}

void ConfigUtil::SetScreenHeight(const int& screenHeight) {
    this->screenHeight_ = screenHeight;
}

const int& ConfigUtil::GetScreenHeight() {
    return screenHeight_;
}

void ConfigUtil::SetScreenWidth(const int& screenWidth) {
    this->screenWidth_ = screenWidth;
}

const int& ConfigUtil::GetScreenWidth() {
    return screenWidth_;
}